﻿using System;
using System.Collections.Generic;
using System.Configuration; 
using System.Linq;
using System.Net;
using System.Net.Configuration;
using System.Net.Security;
using System.Net.Mail;
using System.Text; 
using System.Web;
using System.Web.Configuration;
using System.Web.Security;

/// <summary>
/// Summary description for MailSender
/// </summary>
/// 

public class mailProcessor
{
        
    public SmtpClient smtp_client = new SmtpClient();
    public string sender; 
    
    public mailProcessor()
	{
        Configuration ConfigurationFile = WebConfigurationManager.OpenWebConfiguration("/Deimos");
        MailSettingsSectionGroup MailSettings = ConfigurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;

        smtp_client.Host = MailSettings.Smtp.Network.Host;
        smtp_client.Port = MailSettings.Smtp.Network.Port;
        smtp_client.UseDefaultCredentials = MailSettings.Smtp.Network.DefaultCredentials;

        NetworkCredential smtp_creds = new NetworkCredential(MailSettings.Smtp.Network.UserName, MailSettings.Smtp.Network.Password);

        smtp_client.Credentials = smtp_creds;
        sender = MailSettings.Smtp.From;
    
	}

    public void SendActivationLink(string recipient, string link)
    {
        StringBuilder sb = new StringBuilder();

        sb.Append("Message with activation link!");
        sb.AppendLine(link);

        MailAddress From = new MailAddress(sender);
        MailAddress To = new MailAddress(recipient);

        MailMessage activation_message = new MailMessage(From, To);

        activation_message.Subject = "YourCompany activation link";
        activation_message.Body = sb.ToString();

        smtp_client.Send(activation_message);
    }

    public void SendPasswordReminder(string recipient)
    {
        MailAddress From = new MailAddress(sender);
        MailAddress To = new MailAddress(recipient);

        MailMessage reminder_message = new MailMessage();

        reminder_message.Subject = "YourCompany password reminder";
        reminder_message.Body = "Message with forgotten password!";

        smtp_client.Send(reminder_message);
    }

       
}